﻿(function() {
	var networkInterfaceListWidget = new Class({
		initialize: function(interfaceItems) {
			if (!(interfaceItems && interfaceItems.length > 0))
				return undefined;
				
			this.interfaceListId = 'interfaceList';
			this.interfaces = interfaceItems;

			var interfaceElements = this.interfaces.map(function(interface) {
				var interfaceName = interface.getElementsByTagName('D:displayname')[0];
				var relativePath = interface.getElementsByTagName('D:href')[0];
				if (interfaceName) {
					var interfaceElement = (new Element('div')).grab(new Element('a', {
						'href': sharpbar.applicationUrl + relativePath.firstChild.nodeValue,
						'text': interfaceName.firstChild.nodeValue
					}));
					return interfaceElement;
				} else
					return null;
			});
						
			var interfaceList = new Element('div', { 'id': this.interfaceListId, 'class': 'element' });
			interfaceList.adopt(interfaceElements);
			return interfaceList;
		}
	});
	sharpRegistry.widgets['networkInterface'] = networkInterfaceListWidget;
})();
